/**
 * Created by CK on 2016/7/4.
 */
var schoolId;
var groupId;
var inList;
var outList;
var btnIn;
var btnOut;
$(document).ready(function() {
    schoolId  = xhTool.getQuery('iSchoolId');
    groupId   = xhTool.getQuery('iSAGId');
    inList  = $('#InList');
    outList = $('#OutList');
    btnIn   = $('#bt_in');
    btnOut  = $('#bt_out');
    var DataGrid2 = new DataGridEvent();
    inList.initDataGrid('getGroupAppDgData', {"queryParams": {"iSchoolId": schoolId, "iSAGId": groupId, "type": "in"}})
        .setSelectThenEnable(['bt_out'], [], 'bs');
    outList.initDataGrid('getGroupAppDgData', {"queryParams": {"iSchoolId": schoolId, "iSAGId": groupId, "type": "out"}}, DataGrid2)
        .setSelectThenEnable(['bt_in'], [], 'bs', DataGrid2);
    btnIn.click(function(){
        ids = outList.getDataGridSelectedFields('iSASId');
        contactSchoolGroupApp('in');
    });
    btnOut.click(function(){
        ids = inList.getDataGridSelectedFields('iSASId');
        contactSchoolGroupApp('out');
    });
});
function contactSchoolGroupApp(type) {
    $.post('contactGroupSchoolApp', {iSchoolId:schoolId, iSAGId:groupId, ids:ids, type: type}, function (result) {
        if(result != 'success') {
            $('body').append(result);
            return false;
        }
        inList.dataGridReload();
        outList.dataGridReload();
        btnIn.add(btnOut).setButtonDisable('eu');      //按钮变为禁用状态
    });
}
//关联或取消关联后
//function AfterContact(){
//    //刷新列表并取消勾选
//    dataGridReload('InList');
//    dataGridReload('OutList');
//    //按钮变为禁用状态
//    setButtonDisable('bt_in,bt_out','eu');
//}